<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@page import="java.util.Date"%>
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
 <c:set var="date" value="<%=new Date() %>"/> 
<fmt:formatDate var ="today" value="${date }" type="date" pattern="yyyyMMdd"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link type="text/css" href="/${initParam.context_root }/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet"></link>
<script type="text/javascript" src="/${initParam.context_root }/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/${initParam.context_root }/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#date").datepicker();	
	$("#date").datepicker("option", "dateFormat", "yy-mm-dd");
	$("#date").bind("change",function(){
		var today = ${today};
		var compareToday = window.parseInt(today);
		var saleDate=this.value;
		var inputDate = saleDate.substring(0,4)+saleDate.substring(5,7)+saleDate.substring(8,10);
		if(compareToday<inputDate){
			alert("선택한 구매날짜가 오늘날짜보다 큽니다.\n 다시 선택해 주세요. ");
			return false;
		}
	});
});

	function chkPriceNum(){
		var pp = saleinput.productPrice;
		
		var flagP = window.isNaN(pp.value);
		if(flagP){
			alert("상품가격에 숫자를 입력해 주세요.");
			return false;
		}
	}
	function chkReducedNum(){
		var rp = saleinput.reducedPrice;
		
		var flagR = window.isNaN(rp.value);
		if(flagR){
			alert("쿠폰가격에 숫자를 입력해 주세요.");
			return false;
		}
	}
	function chkQuantityNum(){
		var q = saleinput.quantity;
		
		var flagQ = window.isNaN(q.value);
		if(flagQ){
			alert("수량에 숫자를 입력해 주세요.");
			return false;
		}
	}
	function chkInput(){
		var pp = saleinput.productPrice;
		
		var flagP = window.isNaN(pp.value);
		if(flagP){
			alert("상품가격에 숫자를 입력해 주세요.");
			return false;
		}
		var rp = saleinput.reducedPrice;
		
		var flagR = window.isNaN(rp.value);
		if(flagR){
			alert("쿠폰가격에 숫자를 입력해 주세요.");
			return false;
		}
		var q = saleinput.quantity;
		
		var flagQ = window.isNaN(q.value);
		if(flagQ){
			alert("수량에 숫자를 입력해 주세요.");
			return false;
		}
		
		var namechk = saleinput.productName;
		if(namechk.value==""){
			alert("상품명을 입력해 주세요.");
			return false;
		} 
		if(pp.value==""){
			alert("상품가격을 입력해 주세요.");
			return false;
		}
		if(rp.value==""){
			alert("쿠폰가격을 입력해 주세요.");
			return false;
		}
		if(q.value==""){
			alert("수량을 입력해 주세요.");
			return false;	
		}
		if($("#date").val()==""){
			alert("구매 날짜를 입력해 주세요.");
			return false;	
		}
		
	}
	
</script>

<h2>구매 상품 입력</h2>
<input type="button" value="검색하여 입력하기" onclick="location.href='/${initParam.context_root}/saleSearch.do'"> &nbsp;&nbsp;<input type="button" value="직접입력하기" onclick="location.href='/${initParam.context_root}/saleInput.do'">
<hr>
<form action="/${initParam.context_root}/saleRegister.do" name="saleinput" method="post" onsubmit="return chkInput()" enctype="multipart/form-data" >
	<table border=2 cellpadding=10 width=700px>
	<tr>
	<th colspan="2" bgcolor="lightgray" ><font size=4px >구매내역 검색 후 입력</font></th>
	</tr>
		<tr>
			<td bgcolor="lightgray" width=100px><b>상품명</b>
			</td>
			<td align="left"><input type="text" name="productName" maxlength=10 value="${requestScope.pdto.productName }" readonly="readonly">
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray" width=100px><b>구매사이트</b>
			</td>
			<td align="left"><label><input type="radio" name="siteName" checked="checked" value="쿠팡">쿠팡</label>&nbsp;
			<label><input type="radio" name="siteName" value="티몬">티몬</label>&nbsp;
			<label><input type="radio" name="siteName" value="위메프">위메프</label>&nbsp;
			<label><input type="radio" name="siteName" value="그루폰">그루폰</label>&nbsp;
			<label><input type="radio" name="siteName" value="기타">기타</label>&nbsp;
		</td>
		</tr>
		<tr>
			<td bgcolor="lightgray" width=100px><b>지역</b>
			</td>
			<td align="left"><label><input type="radio" name="location" checked="checked" value="서울">서울</label>&nbsp;
			<label><input type="radio" name="location" value="경기 인천">경기 인천</label>&nbsp;
			<label><input type="radio" name="location"  value="부산">부산</label>&nbsp;
			<label><input type="radio" name="location" value="강원도">강원도</label>&nbsp;
			<label><input type="radio" name="location" value="충청도">충청도</label>&nbsp;
			<label><input type="radio" name="location" value="경상도">경상도</label>&nbsp;
			<label><input type="radio" name="location" value="전라도">전라도</label>&nbsp;
		</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>상품가격</b>
			</td>
			<td align="left"><input type="text" name="productPrice" maxlength=8 onchange="chkPriceNum()" value="${requestScope.pdto.originalPrice }" readonly="readonly"> 원
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>쿠폰가격</b>
			</td>
			<td align="left"><input type="text" name="reducedPrice" maxlength=8 onchange="chkReducedNum()" value="${requestScope.pdto.reducedPrice}" readonly="readonly"> 원
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>구입(매)수</b>
			</td>
			<td align="left"><input type="text"  name="quantity" maxlength=3 onchange="chkQuantityNum()"> (매)개
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>구매일자</b>
			</td>
			<td align="left"><input type="text" value="${today }" name="saleDate"  id="date" readonly="readonly">
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>메모</b>
			</td>
			<td align="left"><textarea cols="50" rows="3" name="memo" ></textarea>
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>사진</b>
			</td>
			<td align="left"><input type="hidden" name="productImage" value="${requestScope.pdto.productImageFilename}"><img src="/${initParam.context_root }/upfile/${requestScope.pdto.productImageFilename}" width="80" height="50">
			</td>
		</tr>
		<tr>
		<td colspan="2"><input type="submit" value="구매내역등록"> <input type="reset" value="취소"> 
		</td>
		</tr>
	</table>
	</form>
